package com.jhgsys.internal.accident.service.impl;

import com.jhgsys.internal.accident.entity.HazardExamineAuditRecord;
import com.jhgsys.internal.accident.mapper.HazardExamineAuditRecordMapper;
import com.jhgsys.internal.accident.service.IHazardExamineAuditRecordService;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.utils.FebsUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.StringPool;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 *  Service实现
 *
 * @author zhangwei
 * @date 2024-08-22 17:39:19
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class HazardExamineAuditRecordServiceImpl extends ServiceImpl<HazardExamineAuditRecordMapper, HazardExamineAuditRecord> implements IHazardExamineAuditRecordService {

    /**
     * 查询（分页）
     * @author zhangwei
     * @date 2024-08-22 17:39:19
     * @param request QueryRequest
     * @param hazardExamineAuditRecord hazardExamineAuditRecord
     * @return IPage<HazardExamineAuditRecord>
    */
    @Override
    public IPage<HazardExamineAuditRecord> findHazardExamineAuditRecordPage(QueryRequest request, HazardExamineAuditRecord hazardExamineAuditRecord) {
        LambdaQueryWrapper<HazardExamineAuditRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HazardExamineAuditRecord::getDeletedFlg, 0);
        // TODO 设置查询条件

        Page<HazardExamineAuditRecord> page = new Page<>(request.getPageNum(), request.getPageSize());
        FebsUtil.pageWrapper(page, request);
        return this.page(page, queryWrapper);
    }

    /**
     * 查询（所有）
     * @author zhangwei
     * @date 2024-08-22 17:39:19
     * @param hazardExamineAuditRecord hazardExamineAuditRecord
     * @return List<HazardExamineAuditRecord>
     */
    @Override
    public List<HazardExamineAuditRecord> findHazardExamineAuditRecordList(HazardExamineAuditRecord hazardExamineAuditRecord) {
	    LambdaQueryWrapper<HazardExamineAuditRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HazardExamineAuditRecord::getDeletedFlg, 0);
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    /**
    * 根据ID查询
    * @author zhangwei
    * @date 2024-08-22 17:39:19
    * @param id
    * @return HazardExamineAuditRecord
    */
    @Override
    public HazardExamineAuditRecord findHazardExamineAuditRecordById(String id){
        return this.baseMapper.selectById(id);
    }

    /**
     * 新增
     * @author zhangwei
     * @date 2024-08-22 17:39:19
     * @param hazardExamineAuditRecord hazardExamineAuditRecord
     */
    @Override
    @Transactional
    public void createHazardExamineAuditRecord(HazardExamineAuditRecord hazardExamineAuditRecord) {
        hazardExamineAuditRecord.setCreatedTime(new Date());
        this.save(hazardExamineAuditRecord);
    }

    /**
     * 修改
     * @author zhangwei
     * @date 2024-08-22 17:39:19
     * @param hazardExamineAuditRecord hazardExamineAuditRecord
     */
    @Override
    @Transactional
    public void updateHazardExamineAuditRecord(HazardExamineAuditRecord hazardExamineAuditRecord) {
        hazardExamineAuditRecord.setUpdatedTime(new Date());
        this.saveOrUpdate(hazardExamineAuditRecord);
    }

    /**
     * 逻辑删除
     * @author zhangwei
     * @date 2024-08-22 17:39:19
     * @param hazardExamineAuditRecord hazardExamineAuditRecord
     * @param hazardExamineAuditRecordIds hazardExamineAuditRecordIds
     */
    @Override
    @Transactional
    public void deleteHazardExamineAuditRecord(HazardExamineAuditRecord hazardExamineAuditRecord,String hazardExamineAuditRecordIds) {
        List<String> list = Arrays.asList(hazardExamineAuditRecordIds.split(StringPool.COMMA));
        this.baseMapper.update(hazardExamineAuditRecord,new LambdaQueryWrapper<HazardExamineAuditRecord>().in(HazardExamineAuditRecord::getExamineAuditRecordId,list));
	}

    /**
    * 物理删除
    * @author zhangwei
    * @date 2024-08-22 17:39:19
    * @param hazardExamineAuditRecordIds hazardExamineAuditRecordIds
    */
    @Override
    @Transactional
    public void physicallyDeleteHazardExamineAuditRecord(String hazardExamineAuditRecordIds) {
        List<String> list = Arrays.asList(hazardExamineAuditRecordIds.split(StringPool.COMMA));
        LambdaQueryWrapper<HazardExamineAuditRecord> wapper = new LambdaQueryWrapper<>();
        wapper.in(HazardExamineAuditRecord::getExamineAuditRecordId,list);
        this.remove(wapper);
    }
}
